﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace DARE
{
     [AttrTypeDependentSerializable(typeof(CConeEmitterData))]
    public class CConeEmitter: AEmitter
    {
        #region properties

        public float Ray { get; set; }
        public float Angle { get; set; }
        public bool EdgeSpawn { get; set; }

        #endregion

        #region ctor

        public CConeEmitter(string name)
            :base(name)
        {

        }

        #endregion

        #region methods

        public override AEmitter Clone()
        {
            CConeEmitter pe = new CConeEmitter(Name);
            pe.EmissionInterval = EmissionInterval;
            pe.EmitPerEmission = EmitPerEmission;
            pe.MaxParticlesSimultaneous = MaxParticlesSimultaneous;
            pe.ReferenceParticle = ReferenceParticle;
            pe.Ray = Ray;
            pe.Angle = Angle;
            pe.EdgeSpawn = EdgeSpawn;
            return pe;
        }

        public override void GetParametersFromEmitter(IParticle particle)
        {
            m_transformNode.Position = m_node.Position;
            m_transformNode.Orientation = m_node.Orientation;
            float ray = Ray;
            if (!EdgeSpawn)
                ray = CDare.Instance.Random.Next((int)(ray * 1000)) / 1000.0f;
            Vector3 pointPos = Vector3.Transform(new Vector3(ray, 0, 0), Quaternion.CreateFromAxisAngle(new Vector3(0, 1, 0), CDare.Instance.Random.Next(36000) / 100.0f));

            m_transformNode.Translate(new Vector3(pointPos.X, 0, pointPos.Z), CNode.ESpace.LOCAL);

            particle.Position = m_transformNode.Position;

            Vector3 vec = Vector3.Normalize(m_node.Position - particle.Position);

            Vector3 dir = Vector3.Transform(vec, Quaternion.CreateFromAxisAngle(new Vector3(-vec.Z, 0, vec.X), Angle)) * Velocities;

            particle.Velocities = dir;
        }
        
        #endregion
    }
}
